import GroupService from "../service/GroupService"
import GroupStore from "../store/GroupStore"
import { ElMessage } from 'element-plus';
//预约记录
export interface Groups {
    GroupList(coachId: number, limit: number, page: number, callback: any): void;
    GroupAll(bookId: number, getGroupAll: any): void;
    UserCheckIn(id: number,getGroupAll:any,bookId:number): void;
    Cancel(id: number,getGroupAll:any,bookId:number): void;
    GroupListData(tableList: any): void;
    groupClassList(callback: any): void;
    getGroupCompile(id: number, callback: any): void;
    getGroupListDel(id: number,callback:any): void;
    getCourseEnquiry(limit:number,name:string,page:number,tableList:any):void;
    getScheduleId(scheduleId:number,schedule:any):void;
    getGroupCourseAdded(data:object):void;
    getGroupCourseEditor(data:object,id:number):void;
    getCoachList(coachList:any):void;
    getCourseFindById(id:number,callback:any):void;
    getCourseUpdateList(id:number,obj:object):void;
    getCourseAddCourseSchedule(obj:object):void

}
export function GroupHooks(): Groups {
    const store = GroupStore()
    //预约记录列表数据
    function GroupList(coachId: number, limit: number, page: number, callback: any) {
        console.log("传入hook",{coachId,limit,page})
        GroupService.getAppointmentBook(coachId, limit, page).then((res: any) => {
            console.log(res)
            if (res.data.code == 0) {
                callback(res.data.data)
            }
            
        })
    }

    //预约记录用户列表数据
    function GroupAll(bookId: number, getGroupAll: any) {
        GroupService.getAppointmentBookAll(bookId).then((res: any) => {
            console.log(res)
            if (res.data.code == 0) {
                getGroupAll(res.data.data)
            }
           
        })
    }
    //预约记录用户签到
    function UserCheckIn(id: number,getGroupAll:any,bookId:number) {
        GroupService.getUserCheckIn(id).then((res: any) => {
            // console.log(res)
            if (res.data.code == 0) {
                ElMessage({ type: "success", message: res.data.msg })
                GroupAll(bookId,getGroupAll)
            } else {
                ElMessage(res.data.msg)
            }
        }).catch((err: any) => {
            ElMessage.error("请求失败");
        })
    }
    //取消预约
    function Cancel(id: number,getGroupAll:any,bookId:number) {
        GroupService.getCancel(id).then((res: any) => {
            // console.log("res",res)
            if (res.data.code == 0) {
                ElMessage({ type: "success", message: res.data.msg })
                GroupAll(bookId,getGroupAll)
            } else {
                ElMessage(res.data.msg)
            }
        }).catch((err: any) => {
            ElMessage.error("请求失败");
        })
    }
    //团课课程数据
    function GroupListData(tableList: any) {
        GroupService.getGroupListData().then((res: any) => {
            console.log(res)
            if (res.data.code == 0) {
                tableList(res.data.data)
            }
        })
    }
    //团课课表数据
    function groupClassList(callback: any) {
        GroupService.groupClassSchedule().then((res: any) => {
            // console.log(res);
            if (res.data.code == 0) {
                callback(res.data.data, res.data.count)
            }
        })
    }
//团课课表回显getCourseFindById
function getCourseFindById(id:number,callback:any) {
    GroupService.getCourseFindById(id).then((res: any) => {
        // console.log(res);
        if (res.data.code == 0) {
            callback(res.data.data)
        }
    })
}
//课表编辑
function getCourseUpdateList(id:number,obj:object) {
    GroupService.getCourseUpdateList(id,obj).then((res: any) => {
        console.log(res);
        if (res.data.code == 0) {
            ElMessage({ type: "success", message: res.data.msg })
        }
    })
}

//课表添加

function getCourseAddCourseSchedule(obj:object) {
    GroupService.getCourseAddCourseSchedule(obj).then((res: any) => {
        console.log(res);
        if (res.data.code == 0) {
            ElMessage({ type: "success", message: res.data.msg })
        }
    })
}





    //团课课程修改回显数据根据id查
    function getGroupCompile(id: number, compileList: any) {
        GroupService.getGroupCompile(id).then((res: any) => {
            console.log("id",res)
            if (res.data.code == 0) {
                compileList(res.data.data)
            }
        })
    }



    //团课课程删除
    function getGroupListDel(id: number,callback:any) {
        GroupService.getGroupListDel(id).then((res: any) => {
            // console.log(res)
            if (res.data.code == 0) {
                ElMessage({ type: "success", message: res.data.msg })
                GroupListData(callback)
            } else {
                ElMessage(res.data.msg)
            }
        }).catch((err: any) => {
            ElMessage.error("请求失败");
        })
    }
    //课程名称模糊查询
    function getCourseEnquiry(limit:number,name:string,page:number,tableList:any){
        GroupService.getCourseEnquiry(limit,name,page).then((res:any)=>{
            // console.log("查询信息",res)
            if(res.data.code==0){
                // ElMessage({ type: "success", message: res.data.msg })
                tableList(res.data.data)
            }else{
                ElMessage(res.data.msg)
            }
        }).catch((err:any)=>{
            ElMessage.error("请求失败")
        })
    }
    //预约记录课程详情信息
    function getScheduleId(scheduleId:number,schedule:any){
        GroupService.getScheduleId(scheduleId).then((res:any)=>{
            // console.log("查询信息",res)
            if(res.data.code==0){
                // ElMessage({ type: "success", message: res.data.msg })
                schedule(res.data.data)
            }else{
                ElMessage(res.data.msg)
            }
        }).catch((err:any)=>{
            ElMessage.error("请求失败")
        })
    }
    //团课课程添加
    function getGroupCourseAdded(data:object){
     GroupService.getGroupCourseAdded(data).then((res:any)=>{
        console.log(data)
        if(res.data.code==0){
            ElMessage({ type: "success", message: res.data.msg })
        }else{
            ElMessage(res.data.msg)

           }
     }).catch((err:any)=>{
        ElMessage.error("请求失败")
    })
    }
    //团课课程编辑
    function getGroupCourseEditor(data:object,id:number){
        GroupService.getGroupCourseEditor(data,id).then((res:any)=>{
           console.log(res)
           if(res.data.code==0){
            ElMessage({ type: "success", message: res.data.msg })
           }else{
            ElMessage(res.data.msg)
           }
        }).catch((err:any)=>{
            ElMessage.error("请求失败")
        })
       }
//团课课程添加页面教练
function getCoachList(coachList:any){
    GroupService.getCoachList().then((res:any)=>{
       if(res.data.code==0){
        console.log(res.data.data)
        coachList(res.data.data)
       }
    })
}
    return {
        GroupList,
        GroupAll,
        UserCheckIn,
        Cancel,
        GroupListData,
        groupClassList,
        getGroupCompile,
        getGroupListDel,
        getCourseEnquiry,
        getScheduleId,
        getGroupCourseAdded,
        getGroupCourseEditor,
        getCoachList,
        getCourseFindById,
        getCourseUpdateList,
        getCourseAddCourseSchedule,
    }
}